USE [Bases2]
GO
/****** Object:  StoredProcedure [dbo].[CrearFolio]    Script Date: 11/29/2011 10:27:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[CrearFolio]    
	@id_banco int
AS 
BEGIN
	SET NOCOUNT ON
	BEGIN TRANSACTION 	
	
	DECLARE @contador int	
	
	SELECT TOP(1) @contador=FOLIO.id_folio
	FROM FOLIO
	ORDER BY FOLIO.id_folio DESC
		
	IF @contador IS NULL
	BEGIN
		SET @contador=-1
	END
	SET @contador=@contador+1
				
	INSERT INTO FOLIO VALUES(@contador,GETDATE(),@id_banco)						
			
	SELECT @contador
	COMMIT
	SET NOCOUNT OFF
END
